# coding:utf-8

from marshmallow import fields

from .utils import EmptyStrValidator
from ..extensions import ma


class DemandIdSchema(ma.Schema):
    """
    created by chenhj at 2017/8/15

    """
    id = fields.Int(required=True, error_messages={
        'required': '需求id不合法'
    })

demand_id_schema = DemandIdSchema()


class CmtSchema(ma.Schema):
    """
    created by chenhj at 2017/8/15

    """
    uid = fields.Int()
    content = fields.Str()
    created_at = fields.Int()

cmts_schema = CmtSchema(many=True)


class DemandUserSchema(ma.Schema):
    """
    created by chenhj at 2017/8/15

    """
    id = fields.Int()
    id_ = fields.Int(attribute='id')
    mobile = fields.Str()
    nickname = fields.Str()
    gender = fields.Int()
    prov = fields.String()
    city = fields.String()

demand_user_schema = DemandUserSchema()


class DemandDetailInfoSchema(ma.Schema):
    """
    created by chenhj at 2017/8/15

    """
    supplier_partic_status = fields.Int(default=0)

demand_detail_info_schema = DemandDetailInfoSchema()


class DemandFinishImgSchema(ma.Schema):
    """
    add by zhouhl 2017-09-06
    """
    demand_id = fields.Int()
    img = fields.Str(required=True, error_messages={
        'required': 'img不合法'
    }, validate=EmptyStrValidator(error='img不合法'))

demand_finish_img_schema = DemandFinishImgSchema()


class ParticFollowSchema(ma.Schema):
    """
    created by chenhj at 2017/12/1

    """
    nickname = fields.Str()
    mobile = fields.Method('get_supplier_mask_mobile')
    follow_type = fields.Int()
    follow_msg = fields.Str()
    user_id = fields.Int()

    def get_supplier_mask_mobile(self, obj):
        """
        created by chenhj at 2017/9/27

        """
        return '****' + obj.mobile[-4:]

partic_follow_list_schema = ParticFollowSchema(many=True)


class EnterpriseDispatchInSchema(ma.Schema):
    """
    created by chenhj at 2018/8/9
    
    """
    query_type = fields.Int(required=True, error_messages={
        'required': '查询类型不合法'
    })
    # 自定义查询月份,若传99,则表示全部
    self_month = fields.Int()
    # 排序值(最后一条数据的发布时间),默认为0
    sort_value = fields.Int(default=0)

enterprise_dispatch_in_schema = EnterpriseDispatchInSchema()


class EnterpriseDispatchExportSchema(EnterpriseDispatchInSchema):
    """
    created by chenhj at 2018/8/9

    """
    email = fields.Email(required=True, error_messages={
        'required': '邮箱地址不合法',
        'invalid': '邮箱地址不合法',
    })

enterprise_dispatch_export_schema = EnterpriseDispatchExportSchema()


class EnterpriseDispatchOutSchema(ma.Schema):
    """
    created by chenhj at 2018/8/10

    """
    id = fields.Int()
    id_ = fields.Int(attribute='id')
    cate = fields.Int()
    malf = fields.Int()
    type = fields.Int()
    surr = fields.Int()
    size = fields.Float()
    color = fields.Int()
    span = fields.Str()
    published_at = fields.Int()
    published_count = fields.Int()
    scan_count = fields.Int()
    budget = fields.Float()
    prov = fields.Str()
    city = fields.Str()
    owner = fields.Str(attribute='owner.nickname')
    remark = fields.Str()
    status = fields.Int()

enterprise_dispatch_out_schema = EnterpriseDispatchOutSchema(many=True)
